/*
 * MusicLabs, Copyright (C) 2008-2009 Felippe Ragghianti
 * http://code.google.com/p/musiclabs
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
 */


package br.com.music.scale;

import br.com.music.Interval;
import java.util.List;

import br.com.music.Pitch;

// XXX : toString should perhaps return a playable text?
// TODO: BlueScale (+.getBlueNote();)

/**
 *  Scale is a series of either ascendent or decendent sounds in which the
 *  latest is a repetition of the same note one octave bellow/above. A scale
 *  can be either <code>{@link MajorScale}</code> or <code>{@link MinorScale}
 *  </code>.
 *
 * @version $LastChangedRevision$
 */
public abstract class Scale {

    /** Root note. */
    Pitch tonic;

    /** All notes that the scale encompasses. */
    List<Pitch> notes;

    /** List of notes intervals. */
    static public List<Interval> intervals;


    /**
     * Class package constructor.
     *
     * @param tonic
     */
    Scale(Pitch tonic) {
        this.tonic = tonic;
        this.notes = this.createScale();
    }

    /**
     * Get the note of given {@link Integer} degree within scale.
     *
     * @param degree Note degree within scale.
     * @return The note of given degree.
     */
    public Pitch getNote(Integer degree) {
        return this.notes.get(degree);
    }

    /**
     *  Get the note of given {@link Degree} within scale.
     *
     * @param degree Note degree within scale.
     * @return The note of given degree.
     */
    public Pitch getNote(Degree degree) {
        if(this.notes == null) {
            this.createScale();
        }
        return this.getNote(degree.toInteger());
    }

    /**
     * Get List of {@link Note}s that are encompassed by this Scale.
     *
     * @return A list of notes.
     */
    public List<Pitch> getNotes() {
        if(this.notes == null) {
            this.createScale();
        }
        return this.notes;
    }

    /**
     * By calling this method a Scale populates the list of nodes with
     * all the elements it encompasses.
     *
     * All scales must implement this method.
     *
     * @return List of notes within this scale.
     */
    protected abstract List<Pitch> createScale();
}
